/**
 * <p>Title: IPostDao.java</p>
 * <p>Description: DoNotes</p>
 * @author WangJun
 * @date 2009/11/15 19:44:00
 * @version 1.0
 */
package net.donotes.blog.dao;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.jdo.PersistenceManager;
import javax.jdo.Query;

import net.donotes.blog.pojo.Ing;
import net.donotes.util.dao.PMF;

/**
 * @author WangJun
 *
 */
public class IngDao {
	/**
	 * Title: addPost
	 * @param post
	 */
	public void addIng(Ing ing) {
		PersistenceManager pm = PMF.get().getPersistenceManager();
        try {
        	ing.setCreateDate(new Date());
            pm.makePersistent(ing);
        } finally {
            pm.close();
        }
	}
	
	/**
	 * Title: delPost
	 * @param post
	 */
	public void delIng(Ing ing) {
		// TODO Auto-generated method stub
	}
	
	/**
	 * 
	 * Title: getPost
	 * @param id
	 */
	public Ing getIng(Long id) {
		Ing ing = new Ing();
		return ing;
	}
	
	/**
	 * Title: updPost
	 * @param post
	 */
	public void updIng(Ing ing) {
	    PersistenceManager pm = PMF.get().getPersistenceManager();
	    try {
	    	Ing t = pm.getObjectById(Ing.class, ing.getId());
	    	t.setContent(ing.getContent());
	    	
	    	pm.makePersistent(ing);
	    } finally {
	        pm.close();
	    }
	}
	
	/**
	 * Title: listPost
	 * @return
	 */
	public List<Ing> listIngs(long rangeFrom, long rangeTo) {
		List<Ing> ings = new ArrayList<Ing>();
		PersistenceManager pm = PMF.get().getPersistenceManager();
		Query query = pm.newQuery(Ing.class);

		query.setRange(rangeFrom, rangeTo);
		query.setOrdering("createDate desc");
	    try {
	    	ings = (List<Ing>) query.execute();
	    } finally {
	        query.closeAll();
	        //pm.close();
	    }
		return ings;
	}
}